{! extends "base.html" !}
{! block hscript !}
<script type="text/javascript" src="{{site.url}}js/jquery.min.js"></script>
{! endblock !}
{! block nav !}
			<a href="{{site.adminUrl}}media/create">Upload new</a>
{! endblock !}
{! block content !}
<div class="wrap">
	<div class="tablenav">
		  <div class="alignleft">&nbsp;</div>
    	  <div class="alignright">
	        {% if pager.prev %}
			<div class="alignleft"><a href="{{site.adminUrl}}media?page={{ pager.prev}}">&laquo; prev</a></div>
			{% endif %}

			{% if pager.next %}
			<div class="alignright"><a href="{{site.adminUrl}}media?page={{ pager.next }}">next &raquo;</a></div>
			{% endif %}
            <div class="alignright" style="padding:0px 10px;">Page {{pager.index}}/{{pager.count}} ({{pager.total}})</div>
         </div>
		      <br class="clear"/>
	   </div>
	  <br class="clear"/>
	  
	 <table class="widefat">
		<thead>
			<tr><th></th><th>Date</th><th>Name</th><th>Mime</th><th>Size<th>&nbsp;</th></tr>
		</thead>
		<tbody>
            {%for media in medias%}
			<tr valign="middle" id="media-{{media.id}}">
			     <td>{{loop.counter}}</td>
                 <td>{{media.creation|date:"yyyy-MM-dd hh:mm:ss"}}</td>
                  <td>{{media.name}}</td>
                  <td>{{media.contentType}}</td>
                  <td>{{media.size}} KB</td>
                  <td><a href="javascript:doDel({{media.id}})">Delete</a></td>
        		</tr>
			{%endfor%}
		</tbody>
	</table>
</div>
{! endblock !}
{! block bscript !}
<script type="text/javascript"> 
function doDel(id) {
 	$.ajax({
 		type: "GET",
 		url: "{{site.adminUrl}}media/delete?id=" + id,
 		dataType: "json",
 		success: function(data){
 			var hmd = $("#hiddenMessage");
	    	if (data.type == "error") {
	    		hmd.html("<div class='error'>" + data.message + "</div>");
	    	} else {
	    		hmd.html("<div class='info'>" + data.message + "</div>");
	    	}
	    	hmd.show().focus();
	    	$("#media-" + id).hide();
 		}
 	});
}
</script> 
{! endblock !}		